package bday.tvlport.db;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.data.mongodb.core.MongoOperations;

import bday.tvlport.utils.LoggerUtility;

public class DbConnection {

	static ApplicationContext ctx = null;

	static MongoOperations mongoOperation = null;
	
	public static MongoOperations getMongo() {
		if(mongoOperation != null) {
			return mongoOperation;
		}
		try {
			if(ctx == null)  {
				ctx = new GenericXmlApplicationContext("SpringConfig.xml");
			}
			if (mongoOperation == null) {
				mongoOperation = (MongoOperations) ctx.getBean("mongoTemplate");
			}
		} catch (BeansException e) {
			LoggerUtility.error(e.toString());
		}
		return mongoOperation;
	}
}